package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingPlan;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.mapper.NursingPlanMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author liangDong
 * @Date 2025-05-09  14:09
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Autowired
    private NursingPlanMapper nursingPlanMapper;

    @Override
    public List<NursingLevelVo> listAll() {
         List<NursingLevelVo> nursingLevelVoList = nursingLevelMapper.selectAll();
        return nursingLevelVoList;
    }

    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setCreateBy(1L);
        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public PageResponse<NursingLevelVo> page(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> nursingLevels = nursingLevelMapper.page(name,status);
        PageResponse<NursingLevelVo> nursingLevelVos = PageResponse.of(nursingLevels,NursingLevelVo.class);
        return nursingLevelVos;
    }

    @Override
    public NursingLevelVo getById(Integer id) {
        Long levelId = Long.valueOf(id);
        return nursingLevelMapper.selectById(levelId);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevel.setUpdateBy(1L);
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void delete(Integer id) {
        nursingLevelMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        Long levelId = Long.valueOf(id);
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevel.setUpdateBy(1L);
        nursingLevel.setId(levelId);
        nursingLevel.setStatus(status);
        nursingLevelMapper.update(nursingLevel);
    }

}
